//
//  CategorySKUCell.m
//  Tang
//
//  Created by 352324497@qq.com on 15/12/7.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CategorySKUCell.h"
#import "CallTool.h"
@implementation CategorySKUCell
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        CGFloat width = frame.size.width;
        self.pic = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, width)];
        [self.contentView addSubview:_pic];
        
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(10 * Kx6, width + 10 * Kx6, width - 20 * Kx6, 30 * Kx6)];
        self.title.textColor = [UIColor darkGrayColor];
        self.title.font = [UIFont systemFontOfSize:16 * Kx6];
        [self.contentView addSubview:_title];
        
        self.price = [[UILabel alloc]initWithFrame:CGRectMake(width - 60 * Kx6, width - 30 * Kx6, 60 * Kx6, 30 * Kx6)];
        self.price.backgroundColor = [UIColor blackColor];
        self.price.alpha = 0.6;
        self.price.textAlignment = NSTextAlignmentCenter;
        self.price.lineBreakMode = NSLineBreakByWordWrapping;
        self.price.textColor = [UIColor whiteColor];
        self.price.font = [UIFont systemFontOfSize:14 * Kx6];
        [self.contentView addSubview:_price];
    }
    return self;
}

-(void)setModel:(CategorySKUModel *)model
{
    _model = model;

    [self.pic sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"PC"]];
    self.title.text = model.title;
    self.price.text = [NSString stringWithFormat:@"¥%@", model.price];
}

-(UIImage *)cutImage:(UIImage *)image WithRegularWidth:(CGFloat)width height:(CGFloat)height{
    
    CGRect cutRect =  CGRectMake(0, self.pic.frame.size.height / 5, width, height);
    
    UIImage *cutImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([image CGImage], cutRect)];
    return cutImage;
}

@end
